package com.looli.common.exception;

import com.looli.common.result.ResponseEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
public abstract class Assert {

    /**
     * 断言对象不为空
     * 如果对象obj为空，则抛出异常
     * @param obj 待判断对象
     */
    public static void notNull(Object obj, ResponseEnum responseEnum) {
        if (obj == null) {
            log.info("obj is null...............");
            throw new BusinessException(responseEnum);
        }
    }

    public static void isNull(Object obj, ResponseEnum responseEnum) {
        if (obj != null) {
            log.info("obj not is null...............");
            throw new BusinessException(responseEnum);
        }
    }


    public static void notEmpty(String obj, ResponseEnum responseEnum) {
        if (obj == null || obj.trim().length() == 0) {
            log.info("obj is null...............");
            throw new BusinessException(responseEnum);
        }
    }

    public static void isTrue(boolean success, ResponseEnum aliyunResponseFail) {
        if (!success) {
            log.error("boolean is false...............");
            throw new BusinessException(aliyunResponseFail);
        }
    }

    public static void notEquals(String s, String code, ResponseEnum aliyunSmsLimitControlError) {
        if (s.equals(code)) {
            log.error(s);
            throw new BusinessException(aliyunSmsLimitControlError);
        }
    }

    public static void equals(Object s, Object code, ResponseEnum aliyunSmsLimitControlError) {
        if (!Objects.equals(s,code)) {
            log.error((String) code);
            throw new BusinessException(aliyunSmsLimitControlError);
        }
    }
}